<?php
use yii\helpers\ArrayHelper;

?>
<form class="layui-form" action="/single-page/edit">
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-inline">
            <input type="text" name="title"
                   value="<?= ArrayHelper::getValue($info, 'title') ?>"
                   lay-verify="required" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">副标题</label>
        <div class="layui-input-inline">
            <input type="text" name="subtitle"
                   value="<?= ArrayHelper::getValue($info, 'subtitle') ?>"
                   lay-verify="required" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">内容</label>
        <div class="layui-input-inline">
            <textarea name="content" class="layui-textarea" id="LAY_demo1"
                      style="display: none"><?= ArrayHelper::getValue($info, 'content') ?></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="hidden" name="<?= Yii::$app->request->csrfParam ?>"
                   value="<?= Yii::$app->request->csrfToken ?>">
            <input type="hidden" name="single_page_id"
                   value="<?= ArrayHelper::getValue($info, 'single_page_id') ?>">
            <button class="layui-btn" lay-submit lay-filter="submit-btn">保存</button>
        </div>
    </div>
</form>
<script>
    layui.use(['layer', 'form', 'layedit'], function () {
        var layer = layui.layer,
            layedit = layui.layedit,
            form = layui.form();
        var textarea1 = layedit.build('LAY_demo1', {
            uploadImage: {url: '/up/image?token=<?=TOKEN?>&path=article', type: 'post'}
        });
        form.on('submit(submit-btn)', function (data) {
            var loading = layer.load(0, {
                shade: <?=Yii::$app->params['layui_shade']?>,
                time: <?=Yii::$app->params['layui_time']?>});
            //增加编辑器内容
            data.field.content = layedit.getContent(textarea1);
            $.post(data.form.action, data.field, function (rs) {
                layer.msg(rs.msg);
                if (rs.code === 0) {
                    setTimeout(function () {
                        window.location.href = rs.redirect;
                    }, <?=Yii::$app->params['layui_set_timeout']?>);
                }
                layer.close(loading);
            }, 'json');
            return false;
        });
    });
</script>